package cn.yzgy.yzgyoa.ucenter.service.impl;

import cn.yzgy.yzgyoa.common.constant.YzCacheName;
import cn.yzgy.yzgyoa.ucenter.entity.SysUserDetail;
import cn.yzgy.yzgyoa.ucenter.entity.UserInfoDetail;
import cn.yzgy.yzgyoa.ucenter.mapper.SysUserDetailMapper;
import cn.yzgy.yzgyoa.ucenter.service.ISysUserDetailService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 用户详情表，包含用户具体身份信息 服务实现类
 * </p>
 *
 * @author Yqsen
 * @since 2019-08-27
 */
@Service
@CacheConfig(cacheNames = YzCacheName.USER_DETAIL_INFO_CACHE_NAME)
public class SysUserDetailServiceImpl extends ServiceImpl<SysUserDetailMapper, SysUserDetail> implements ISysUserDetailService {


    @Override
    @Cacheable(keyGenerator = YzCacheName.GENERATOR_NAME)
    public SysUserDetail getById(Serializable id) {
        return super.getById(id);
    }

    /**
     * 根据用户UID获取用户详细信息
     * @param uid uid
     * @return 用户详细信息
     */
    @Override
    @Cacheable(keyGenerator = YzCacheName.GENERATOR_NAME)
    public UserInfoDetail getUserDetailInfoByUid(Long uid) {
        return baseMapper.getUserDetailInfoByUid(uid);
    }

    /**
     * 新增用户详情数据
     * @param sysUserDetail 用户详情对象
     * @return 影响条数
     */

    @Override
    public int addSysUserDetail(SysUserDetail sysUserDetail) {
        return baseMapper.insert(sysUserDetail);
    }

    @Override
    public int delSysUserDetail(List<String> userId) {
        UpdateWrapper<SysUserDetail> wrapper = new UpdateWrapper<>();
        wrapper.in(true, "uid", userId);
        return baseMapper.delete(wrapper);
    }

    @Override
    public int changeInfo(SysUserDetail sysUserDetail) {
        UpdateWrapper<SysUserDetail> wrapper = new UpdateWrapper<>();
        wrapper.eq("uid", sysUserDetail.getUid());
        return baseMapper.update(sysUserDetail,wrapper);
    }

    @Override
    public String dataPerm(Long uid) {
        return baseMapper.dataPerm(uid);
    }
}
